<?php
require('../../public/connection.php');
require('../../class/Mysql.php');
// checkLogin();
$data = json_decode(file_get_contents('php://input'), true);
if (!$data["size"]) {
    die(json_encode(array("code" => 400, "msg" => "格式错误")));
}
//查询luggage近size条数据
$select_luggage_page_data = new Mysql();
$result_luggage = $select_luggage_page_data->selectPageData(
    "select *  from luggages order by date desc limit {$data['size']};",
    "select count(id) as count  from luggages;"
);

//查询todolist数据
$select_todolist_page_data = new Mysql();
$result_todolist = $select_todolist_page_data->selectPageData(
    "select *  from todolist  where 'finished'=0 order by date desc limit {$data['size']};",
    "select count(id) as count  from todolist;"
);

//查询accounting数据
$select_accounting_page_data = new Mysql();
$result_accounting = $select_accounting_page_data->selectPageData(
    "select *  from accountings order by date desc limit {$data['size']};"
);

//查询日报数据
$select_dailypaper_page_data = new Mysql();
$result_dailypaper = $select_dailypaper_page_data->selectPageData(
    "select *  from dailypaper order by date desc limit {$data['size']};"
);


$select_account_all_data = new Mysql();
$account_data_result = $select_account_all_data->selectAllData("accountings", "money");
$money = 0;
foreach ($account_data_result["data"] as $key => $value) {
    $money += $value["money"];
}

$select_income_all_data = new Mysql();
$income_data_result = $select_income_all_data->selectAllData("incomes", "money");
$income_money = 0;
foreach ($income_data_result["data"] as $key => $value) {
    $income_money += $value["money"];
}
die(json_encode(array(
    "code" => 0,
    "todolist_data" => $result_todolist["data"],
    "todolist_count" => $result_todolist["num"],
    "luggage_data" => $result_luggage["data"],
    "luggage_count" => $result_luggage["num"],
    "dailypaper_data" => $result_dailypaper["data"],
    "accounting_data" => $result_accounting["data"],
    "money" => $money,
    "income_money" => $income_money
)));
